package com.msb.mall.thirdPart.controller.sms;


import com.msb.common.vo.CommonResult;
import com.msb.mall.thirdPart.utils.SmsComponent;
import org.apache.http.HttpStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/thirdPart/sms")
public class SMSController {

    @Autowired
    private SmsComponent smsComponent;

    /**
     * 调用短信服务商提供的短信API发送短信
     * @param phone
     * @param code
     * @return
     */
    @GetMapping("/sendSmsCode")
    public CommonResult sendSmsCode(@RequestParam("phone") String phone, @RequestParam("code") String code){
        CommonResult commonResult = CommonResult.success();
        try {
            smsComponent.sendSmsCode(phone,code);
        } catch (Exception e) {
            commonResult.setCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            commonResult.setMsg(e.getMessage());
        }

        return commonResult;
    }
}
